package top.lshaci.learning.nio.zerocopy;

import lombok.extern.slf4j.Slf4j;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * OldIOClient
 *
 * @author lshaci
 * @since 1.0.0
 */
@Slf4j
public class OldIOClient {

    public static void main(String[] args) throws IOException {
        Socket client = new Socket("127.0.0.1", 6689);
//        String filename = "F:\\迅雷下载\\Docker Desktop Installer.exe"; // 960472784
        String filename = "F:\\System\\Pictures\\background\\-220f944a8e69fcad.jpg";
        FileInputStream inputStream = new FileInputStream(filename);
        DataOutputStream dataOutputStream = new DataOutputStream(client.getOutputStream());

        int readCount;
        int total = 0;
        byte[] buffer = new byte[8192];

        long start = System.currentTimeMillis();
        while ((readCount = inputStream.read(buffer)) != -1) {
            dataOutputStream.write(buffer, 0, readCount);
            total+= readCount;
        }

        long end = System.currentTimeMillis();

        log.debug("发送的总字节数: {}, 耗时: {} ms", total, (end - start));
    }
}
